package pl.game;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.SpriteBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;

public class ManagedScene extends Scene {

	private BitmapTextureAtlas curBitmapTextureAtlas;
	private TextureRegion mFaceTextureRegion;
	private BitmapTextureAtlas  backgroundBitmapTextureAtlas;
	
	private Context curContext;
	Sprite sprite1 ;

	public ManagedScene(BitmapTextureAtlas m, Context c) {
		super();
		curBitmapTextureAtlas = m;
		curContext = c;
		//ustawienie wiekszego BitmapTextureAtlas ze wzgledu na wiekszy wczytywany obraz
		this.backgroundBitmapTextureAtlas = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT);
		this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(curBitmapTextureAtlas, curContext, "gfx/belgica.png", 0, 0);
	     sprite1 = new Sprite(0, 0, this.mFaceTextureRegion);
		 attachChild(sprite1);
			
	}
	
	public void setBackgroundBitmapTextureAtlas(
			BitmapTextureAtlas backgroundBitmapTextureAtlas) {
		this.backgroundBitmapTextureAtlas = backgroundBitmapTextureAtlas;
	}
	

	@Override
	protected void onManagedUpdate(float pSecondsElapsed) {
			
	    super.onManagedUpdate(pSecondsElapsed);
		
		float x = sprite1.getX();
		float y = sprite1.getY();
		sprite1.setPosition(x+1, y);
		if (x == 150){
			
			this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(backgroundBitmapTextureAtlas, curContext, "gfx/europe_flag2.png", 0, 0);
			Sprite backgroundSprite = new Sprite(0, 0, this.mFaceTextureRegion);
			SpriteBackground sb2 = new SpriteBackground(backgroundSprite);			
			this.setBackground(sb2);
			
		}
	}
}



	

